//
/**
 * Filename: pr_mask.c
 * Author:   csbonkers
 * Contact:  forever65535@qq.com
 * Date:     2021/6/19
 * Description:
 *    打印调用进程信号屏蔽字中信号名
 */

#include "apue.h"
#include <errno.h>

void pr_mask(const char *str) {
  sigset_t sigset;
  int errno_save = errno;// we can be called by signal handlers
  if (sigprocmask(0, NULL, &sigset) < 0) {
    err_ret("sigprocmask error");
  } else {
    printf("%s", str);
    if (sigismember(&sigset, SIGINT)) {
      printf(" SIGINT ");
    }
    if (sigismember(&sigset, SIGQUIT)) {
      printf("SIGQUIT ");
    }
    if (sigismember(&sigset, SIGUSR1)) {
      printf("SIGUSR1 ");
    }
    if (sigismember(&sigset, SIGALRM)) {
      printf("SIGALRM ");
    }
    /*remaining signals can go here*/
    printf("\n");
  }
  errno = errno_save;
}